var liList =selet("#tex p")
// console.log(liList)
var sectionList = document.getElementsByTagName('section');
for (var i = 0; i < liList.length; i++) {
    // 自动生成自定义属性
    liList[i].setAttribute("dawei-index", i)
        // 为每一个li绑定单击事件
    liList[i].onclick = function() {
        // 怎么在事件处理函数里代表当前点击的到底是第几个li？
        // this出现在事件处理函数中：它指向的是触发该事件的Node节点	
        // 干掉所有li的class
        for (var j = 0; j < liList.length; j++) {
            liList[j].className = "";
            sectionList[j].className = "";
        }
        this.className = "active";
        // 给当前的li所对应的section的class属性设置成show
        sectionList[this.getAttribute("dawei-index")].className = "show";
    }
}


// 验证登录
// 登录验证
//  <input type="text" name="" placeholder="手机号/邮箱" id="telmailin"/><br>
//  <span id="telemail"></span>
//  </div>
//  <div class="passBox">
//  <input type="password" name="" placeholder="请填写密码" id="passin" /><br>
//  <span id="pass"></span>



let arr1 = [0, 0];
$("#iphone").blur(function() {
// 手机号：15  13  18 开头的11数字
var regObj = /^[a-zA-Z]+$/
if (!regObj.test(this.value)) {
    $("#phone").html("请输入15，13，18开头11位手机号").css({
        "color": "red"
    });
    arr1[0] = 0;
} else {
    $("#phone").html("");
    arr1[0] = 1;
}

});


// 验证验证码是否一致
function fn(){
    arr=["0","1","2","3","4","5","6","7","8","9","a","b","c","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
    result=""
    for(i=0;i<4;i++){
        var index=parseInt(Math.random()*23)
        result=result+arr[index]
    }
    return result;
    
}

$("#change").text(fn());
$("#change").click(function(){
    $("#change").text(fn());
});

// 验证密码格式是否正确
$("#userpass").blur(function() {
let regObj = /^.{6,18}$/;
if (!regObj.test(this.value)) {
    $("#pass").html("密码的格式不合法，请输入6~18位字符").css({
        "color": "red"
    });
    arr1[1] = 0;
} else {
    $("#pass").html("");
    arr1[1] = 1;
}
});
// // 点击登录按钮检验
$("#loadBtn").click(function() {
// 1、判断所有的前端验证没有问题
// every函数：判断数据中的每个元素是否满足条件（回调函数写的条件）
if (!arr1.every(item => item == 1)) {
    $("#loadmsg").html("请仔细检查每一项是否正确").css({
        "color": "red"
    });
} else {
    // 2、发送请求（注册）
    $.ajax({
        url: "php/logon.php",
        type: "post",
        data: {
            "iphone": $("#iphone").val(),
            "userpass": $("#userpass").val()
        },
        success: function(data) {
            console.log(data)
            if (data == 1) {
                saveCookie("iphone",$("#iphone").val());
                let seconds=5;
                let myTimer=setInterval(function(){
                    seconds--;
                    if(seconds<=0){
                        clearInterval(myTimer);
                        location.href="index00.html";
                    }
                    $("#loadmsg").html(`登陆成功!${seconds}秒后跳转到<a href='index00.html'>首页</a>`);
                    // `登录成功！${seconds}秒后跳转到<a href='index.html'>首页</a>`;
                    
                },1000)
            } else {
                $("#loadmsg").html("登录失败！").css({
                    "color": "red"
                });
            }
        }
    })
}
});
